using System;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using Iesi.Collections.Generic;

namespace WineCellar.Data
{
	[ActiveRecord("Raisins", Schema = "dbo", UseAutoImport = false)]
    public partial class Raisin
    {

        private string name;
        private Nullable<DateTime> dateAdded;
        private Nullable<int> id;
        private User addedBy;
    	private ISet<Wine> wines = new HashedSet<Wine>();

        [Property("Name", ColumnType = "String", NotNull = true)]
		[ValidateNonEmpty("Name is a required field")]
		public virtual string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        [Property("DateAdded", ColumnType = "Timestamp")]
		public virtual Nullable<DateTime> DateAdded
        {
            get
            {
                return this.dateAdded;
            }
            set
            {
                this.dateAdded = value;
            }
        }

        [PrimaryKey(PrimaryKeyType.Identity)]
		public virtual Nullable<int> Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        [BelongsTo("UserAdded", NotNull = true)]
        public virtual User AddedBy
        {
            get
            {
                return this.addedBy;
            }
            set
            {
                this.addedBy = value;
            }
        }

		[HasAndBelongsToMany(typeof(Wine), ColumnRef = "WineId", ColumnKey = "RaisinId",
			Table = "Raisins2Wines", RelationType = RelationType.Guess, Lazy = true)]
		public virtual ISet<Wine> Wines
		{
			get { return wines; }
			set { wines = value; }
		}

        public override string ToString()
        {
            return this.Name;
        }
    }
}
